# import unittest
# from ddt import ddt, data
import os
import openpyxl
import shutil
from openpyxl import load_workbook
from conf.set_path import path



class Case:
    def __init__(self):
        self.case_id = None
        self.title = None
        self.url = None
        self.data = None
        self.method = None
        self.expected = None
        self.sql = None


class Do_Excel:
    def __init__(self, filename, sheet_name):
        self.filename = filename
        self.native_cp()
        self.fn = load_workbook(self.filename, )  # 打开文件
        self.sheet_name = sheet_name

        self.sheet = self.fn[self.sheet_name]


    def native_cp(self):
        str_excel_open = r'D:\Pycharm\code\CR\record\report.xlsx'
        if not os.path.exists(self.filename):
            shutil.copyfile(str_excel_open, self.filename)

    def write_excel(self, h,l,val):
        self.sheet.cell(h, l).value = val  # 执行结果
        self.fn.save(filename=self.filename)
        self.fn.close()


excel = Do_Excel(rf"{path.record_path}\report.xlsx", 'Sheet1')
wb = openpyxl.load_workbook((rf"{path.record_path}\report.xlsx"))
asheet = wb['Sheet1']
max_row = asheet.max_row
print(max_row)
row = max_row + 1

if __name__ == '__main__':
    # 写入
    excel = Do_Excel("../report/report.xlsx", 'Sheet1')
    excel.write_excel(l=1,h=2, val="11")
    excel.write_excel(l=1,h=2, val="11")
    excel.write_excel(l=2,h=2, val="02")
    excel.write_excel(l=3,h=2, val="03")
    excel.write_excel(l=4,h=2, val="04")
    excel.write_excel(l=5,h=2, val="05")
